<{include file="public_html/header.html"}>
<{include file="public_html/left_menu.html"}>

<blockquote class="layui-elem-quote"><{$action}></blockquote>

<form class="layui-form layui-form-pane" method="post" action="<{$post_url}>">
    <input type="hidden" name="id" value="<{$chapter_info.id|default:'0'}>" />

    <div class="layui-form-item">
        <label class="layui-form-label">章节名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" value="<{$chapter_info.title|default:''}>" class="layui-input" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">科目</label>
        <div class="layui-input-block">
            <select name="subject_id" id="subject" lay-filter="subject">
                <option value="0">请选择科目</option>
                <{foreach from=$subject_list item=sitem}>
                    <option value="<{$sitem.id}>" <{if isset($chapter_info.subject_id) AND $chapter_info.subject_id == $sitem.id}>selected<{/if}>><{$sitem.title}></option>
                <{/foreach}>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">章节</label>
            <div class="layui-input-block">
                <select name="parent_id" id="chapter_id" lay-filter="chapter_id">
                    <option value="0">请选择章节</option>
                    <{if $chapter_list_data|count  > 0}>
                        <{foreach from=$chapter_list_data item=item}>
                        <{if $item.id != $chapter_info.id}>
                        <option <{if $item.id == $chapter_info.parent_id}> selected <{/if}> value="<{$item.id}>"><{$item.title}></option>
                        <{/if}>
                        <{/foreach}>
                    <{/if}>
                </select>
            </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序：</label>
        <div class="layui-input-block">
            <input type="text" name="sort" onafterpaste="this.value=this.value.replace(/\D/g,'')" onkeyup="this.value=this.value.replace(/\D/g,'')" value="<{$chapter_info.sort|default:'0'}>" lay-verify="title" autocomplete="off" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">是否显示</label>
        <div class="layui-input-block">
            <{assign var="is_chapter" value=$privilege_info->is_chapter|default:"1"}>
            <input type="checkbox" <{if $is_chapter == 1}> checked<{/if}> name="is_chapter" lay-skin="switch" lay-filter="switchTest" value="1" >
        </div>
    </div>

    <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
<{include file="public_html/footer.html"}>
<script type="text/javascript">
    layui.use(['form','jquery'], function(){
        var form = layui.form(),$ = layui.jquery;
        
        form.on('select(subject)', function(data){
            var ii = layer.load();
            var subject_id = $(data.elem).val();
            $("#chapter_id").html('<option value="0">顶级章节</option>');  
            form.render('select');
            $.ajax({
                type: "POST",
                url: "/topic/ignore_get_subject_chapter",
                dataType:"json",
                data:{subject_id:subject_id},
                success: function(result){
                    layer.close(ii);
                    if(result.code == 1){
                        var html ='';
                        $.each(result.chapter_list, function(i, obj) {
                            html += '<option value="'+obj.id+'">'+obj.title+'</option>'
                            /*html += '<optgroup label="'+ obj.title+'">';
                            if(obj.sub){
                                $.each(obj.sub, function(j, obj1) {
                                    html += '<option value="'+obj1.id+'">'+obj1.title+'</option>';
                                });
                            }
                            html += '</optgroup>'*/
                        });
                        $("#chapter_id").append(html);
                        form.render('select');
                    }
                }
            });
        });
    });
</script>